<div class="tmd-doc">
<p></p>
<h1 class="tmd-header-1">
How to iterate runes in a string?
</h1>
<p></p>
<div class="tmd-usual">
In Go, strings are assumed as UTF-8 encoded. Just <code class="tmd-code-span">for-range</code> over a string to get the runes (Unicode code points) in the string.
</div>
<p></p>
<pre class="tmd-code">
<code class="language-Go">	for i, rune := range aString {
		... // use the rune
	}
</code></pre>
<p></p>
<div class="tmd-usual">
A rune might be composed of 1-4 bytes (called the length of the rune) in UTF-8 encoding. Here, <code class="tmd-code-span">i</code> is the start index of the bytes of the rune. The size (count of bytes) of each rune can be got but the process is not very smooth. The following way is more smooth to rune sizes:
</div>
<p></p>
<pre class="tmd-code">
<code class="language-Go">import "unicode/utf8"

	var str = aString
	for {
		rune, size := utf8.DecodeRuneInString(str)
		if size == 0 {
			break
		}
		str = str[size:]
		
		... // use rune
	}
</code></pre>
<p></p>
</div>
